package com.ruoyi.web.controller.storeClaassify;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.storeclassify.domain.Storeclassify;
import com.ruoyi.storeclassify.service.IStoreclassifyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 分类Controller
 *
 * @author ruoyi
 * @date 2021-11-18
 */
@RestController
@RequestMapping("/storeclassify/storeclassify")
public class StoreclassifyController extends BaseController
{
    @Autowired
    private IStoreclassifyService storeclassifyService;

    /**
     * 查询分类列表
     */
    @PreAuthorize("@ss.hasPermi('storeclassify:storeclassify:list')")
    @GetMapping("/list")
    public TableDataInfo list(Storeclassify storeclassify)
    {
        startPage();
        List<Storeclassify> list = storeclassifyService.selectStoreclassifyList(storeclassify);
        return getDataTable(list);
    }
    /**
     * 查询分类列表
     */
    @PreAuthorize("@ss.hasPermi('storeclassify:storeclassify:list')")
    @GetMapping("/list/classify")
    public TableDataInfo listClassify()
    {
        startPage();
        List<Storeclassify> list = storeclassifyService.selectSecondVue();
        return getDataTable(list);
    }
    /**
     * 查询form表单中的分类
     * */
    @PreAuthorize("@ss.hasPermi('storeclassify:storeclassify:second')")
    @GetMapping("/second")
    public List<Storeclassify> getSecond(){
        return storeclassifyService.selectSecond();
    }

    /**
     * 导出分类列表
     */
    @PreAuthorize("@ss.hasPermi('storeclassify:storeclassify:export')")
    @Log(title = "分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Storeclassify storeclassify)
    {
        List<Storeclassify> list = storeclassifyService.selectStoreclassifyList(storeclassify);
        ExcelUtil<Storeclassify> util = new ExcelUtil<Storeclassify>(Storeclassify.class);
        return util.exportExcel(list, "分类数据");
    }

    /**
     * 获取分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('storeclassify:storeclassify:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(storeclassifyService.selectStoreclassifyById(id));
    }

    /**
     * 新增分类
     */
//    @PreAuthorize("@ss.hasPermi('storeclassify:storeclassify:add')")
    @Log(title = "分类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Storeclassify storeclassify)
    {
        storeclassify.setCreateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(storeclassifyService.insertStoreclassify(storeclassify));
    }

    /**
     * 修改分类
     */
    @PreAuthorize("@ss.hasPermi('storeclassify:storeclassify:edit')")
    @Log(title = "分类", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody Storeclassify storeclassify)
    {
        storeclassify.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(storeclassifyService.updateStoreclassify(storeclassify));
    }

    /**
     * 删除分类
     */
    @PreAuthorize("@ss.hasPermi('storeclassify:storeclassify:remove')")
    @Log(title = "分类", businessType = BusinessType.DELETE)
	@PostMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(storeclassifyService.logicDeleteStoreclassify(ids,DicConstants.BUSINESS_Manager.getCode(),SecurityUtils.getUserId()));
    }



}
